/**
 * @file lib.lock.c
 * @author maguannan
 * @date 2013/01/28 20:05:56
 * @brief 
 *      
 **/

#include "base.h"
#include <pthread.h>

int mlock_init(struct mlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_mutex_init(&p_lock->_lock, NULL);
}

int mlock_lock(struct mlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_mutex_lock(&p_lock->_lock);
}

int mlock_unlock(struct mlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_mutex_unlock(&p_lock->_lock);
}

int mlock_trylock(struct mlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_mutex_trylock(&p_lock->_lock);
}

int mlock_destroy(struct mlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_mutex_destroy(&p_lock->_lock);
}

int rwlock_init(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_init(&p_lock->_lock, NULL);
}

int rwlock_rdlock(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_rdlock(&p_lock->_lock);
}

int rwlock_wrlock(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_wrlock(&p_lock->_lock);
}

int rwlock_tryrdlock(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_tryrdlock(&p_lock->_lock);
}

int rwlock_trywrlock(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_trywrlock(&p_lock->_lock);
}

int rwlock_unlock(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_unlock(&p_lock->_lock);
}

int rwlock_destroy(struct rwlock *p_lock){
    ASSERT(p_lock!=NULL);
    return pthread_rwlock_destroy(&p_lock->_lock);
}


/* vim: set tw=0 ts=4 sw=4 et: */
